<?php
/**
 * Created by PhpStorm.
 * User: haodian
 * Date: 2018/7/25
 * Time: 14:42
 */

namespace App\Http\Controllers\Admin;

use App\Base\BaseFunc;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;

class ChangController extends Controller
{
    public function searchGameGL()
    {
        $data['gameGLData'] = DB::table('game_gl')
            ->orderby('game_gl_id','desc')
            ->paginate(10);
        session(['now_address'=>'/searchGameGL']);
        return view('/admin.chang.searchGameGL',$data);
    }

    public function addGameGL(BaseFunc $baseFunc)
    {
        $input = Input::only('game_gl_name','game_gl_info','game_gl_floor');
        $input['game_gl_time'] = date('Y-m-d H:i:s');
        DB::table('game_gl')->insert($input);
        $baseFunc->setRedirectMessage(true,"添加攻略成功！",NULL,"/searchGameGL");
    }

    public function gameGLInfo($id)
    {
        $data['glInfo'] = DB::table('game_gl')
            ->where('game_gl_id',$id)
            ->first();
        return view('/admin.chang.gameGLInfo',$data);
    }

    public function delGameGL(BaseFunc $baseFunc)
    {
        $input = Input::only('game_gl_id');
        $data = DB::table('game_gl')
            ->where('game_gl_id','=',$input['game_gl_id'])
            ->delete();
        if($data)
        {
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/searchGameGL');
        }
        else
        {
            $baseFunc->setRedirectMessage(false,'删除失败',NULL,'/searchGameGL');
        }
    }

    public function searchGameMP()
    {
        $data['gameMPData'] = DB::table('game_mp')
            ->orderby('game_mp_id','desc')
            ->paginate(10);
        session(['now_address'=>'/searchGameMP']);
        return view('/admin.chang.searchGameMP',$data);
    }

    public function addGameMP(BaseFunc $baseFunc)
    {
        $input = Input::only('game_mp_name','game_mp_info','game_mp_floor');
        $input['game_mp_time'] = date('Y-m-d H:i:s');
        DB::table('game_mp')->insert($input);
        $baseFunc->setRedirectMessage(true,"添加门派成功！",NULL,"/searchGameMP");
    }

    public function gameMPInfo($id)
    {
        $data['mpInfo'] = DB::table('game_mp')
            ->where('game_mp_id',$id)
            ->first();
        return view('/admin.chang.gameMPInfo',$data);
    }

    public function delGameMP(BaseFunc $baseFunc)
    {
        $input = Input::only('game_mp_id');
        $data = DB::table('game_mp')
            ->where('game_mp_id','=',$input['game_mp_id'])
            ->delete();
        if($data)
        {
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/searchGameMP');
        }
        else
        {
            $baseFunc->setRedirectMessage(false,'删除失败',NULL,'/searchGameMP');
        }
    }

    public function searchGameJN()
    {
        $data['gameJNData'] = DB::table('game_jn')
            ->orderby('game_jn_id','desc')
            ->paginate(10);
        session(['now_address'=>'/searchGameJN']);
        return view('/admin.chang.searchGameJN',$data);
    }

    public function addGameJN(BaseFunc $baseFunc)
    {
        $input = Input::only('game_jn_name','game_jn_info','game_jn_floor');
        $input['game_jn_time'] = date('Y-m-d H:i:s');
        DB::table('game_jn')->insert($input);
        $baseFunc->setRedirectMessage(true,"添加技能成功！",NULL,"/searchGameJN");
    }

    public function gameJNInfo($id)
    {
        $data['jnInfo'] = DB::table('game_jn')
            ->where('game_jn_id',$id)
            ->first();
        return view('/admin.chang.gameJNInfo',$data);
    }

    public function delGameJN(BaseFunc $baseFunc)
    {
        $input = Input::only('game_jn_id');
        $data = DB::table('game_jn')
            ->where('game_jn_id','=',$input['game_jn_id'])
            ->delete();
        if($data)
        {
            $baseFunc->setRedirectMessage(true,'删除成功',NULL,'/searchGameJN');
        }
        else
        {
            $baseFunc->setRedirectMessage(false,'删除失败',NULL,'/searchGameJN');
        }
    }
}